﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using SqlCon;
namespace yfxt
{
    public partial class ms_cfcx_mx : Form
    {


        ms_cfcx cfcx;
        public ms_cfcx_mx()
        {
            InitializeComponent();
        }



        public string s_temp;

        public string S_temp 
        {
            get { return this.s_temp; }
            set { this.s_temp = value; }
        }
        private void ms_cfcx_mx_Load(object sender, EventArgs e)
        {
            cfcx = (ms_cfcx)this.Owner;


            using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
            {
                string str = "select ypmc,ypgg,ypdw,cdmc,ypdj,ypsl from ms_cf01,ms_cf02,yk_typk,yk_ypcd,yk_cddz  "+
                            " where  ms_cf01.cfsb=ms_cf02.cfsb and yk_typk.ypxh=ms_cf02.ypxh  "+
                            " and yk_typk.ypxh=yk_ypcd.ypxh and yk_cddz.ypcd=yk_ypcd.ypcd  "+
                             "and cfhm=" + cfcx.s_temp.ToString()  +
                             "  group by ypmc,ypgg,ypdw,cdmc,ypdj,ypsl";

                if (conn.State != ConnectionState.Open) { conn.Open(); }

                using (SqlCommand cmd = new SqlCommand(str, conn))
                {

                    SqlDataAdapter da = new SqlDataAdapter();

                    da.SelectCommand = cmd;

                    DataTable dt = new DataTable();

                    da.Fill(dt);

                    dataGridView1.DataSource = dt;

                    dataGridView1.Columns[0].HeaderCell.Value = "药品名称";
                    dataGridView1.Columns[1].HeaderCell.Value = "药品规格";
                    dataGridView1.Columns[2].HeaderCell.Value = "药品单位";
                    dataGridView1.Columns[3].HeaderCell.Value = "药品产地";
                    dataGridView1.Columns[4].HeaderCell.Value = "药品价格";
                    dataGridView1.Columns[5].HeaderCell.Value = "药品数量";
                }

                SqlParameter sp_01, sp_02, sp_03, sp_04, sp_05, sp_06, sp_07, sp_08;

                string str_01 = "select @fphm=ms_cf01.fphm,@brxm=ms_cf01.brxm,@brxz=brxz,@kfrq=kfrq,@ksmc=ksmc,@ygxm=ygxm "+
                                "from ms_cf01,ms_mzxx,gy_ygdm,gy_ksdm  where ms_cf01.cfhm=@cfhm";

                if (conn.State != ConnectionState.Open) { conn.Open(); }

                using (SqlCommand cmd_01 = new SqlCommand(str_01, conn))
                {
                    cmd_01.Parameters.AddWithValue("@cfhm", cfcx.s_temp.ToString());
                    sp_01 = cmd_01.Parameters.Add("@brxm", SqlDbType.NVarChar, 40);
                    sp_02 = cmd_01.Parameters.Add("@brxz", SqlDbType.NVarChar, 20);
                    sp_03 = cmd_01.Parameters.Add("@kfrq", SqlDbType.DateTime, 40);
                    sp_04 = cmd_01.Parameters.Add("@ksmc", SqlDbType.NVarChar, 40);
                    sp_05 = cmd_01.Parameters.Add("@ygxm", SqlDbType.NVarChar, 40);
                    sp_06 = cmd_01.Parameters.Add("@fphm", SqlDbType.NVarChar, 20);

                    sp_01.Direction = ParameterDirection.Output;
                    sp_02.Direction = ParameterDirection.Output;
                    sp_03.Direction = ParameterDirection.Output;
                    sp_04.Direction = ParameterDirection.Output;
                    sp_05.Direction = ParameterDirection.Output;
                    sp_06.Direction = ParameterDirection.Output;

                    cmd_01.ExecuteNonQuery().ToString();


                    tb_brxm.Text = sp_01.Value.ToString();
                    if (sp_02.Value.ToString().Equals("123"))
                    {
                        tb_brzx.Text = "自费";
                    }
                    else
                    {

                        tb_brzx.Text = "医保";
                    }

                    tb_kfrq.Text = sp_03.Value.ToString();

                    tb_fphm.Text = sp_06.Value.ToString();

                    tb_ysxm.Text = sp_05.Value.ToString();

                    tb_ypzs.Text = dataGridView1.Rows.Count.ToString();
                }




                string s_sum = "select @ypzqs=sum(ypsl*ypdj) from ms_cf01,ms_cf02 where ms_cf01.cfsb=ms_cf02.cfsb and cfhm=@cfhm";
                if (conn.State != ConnectionState.Open) { conn.Open(); }
                using (SqlCommand cmd_02 = new SqlCommand(s_sum, conn))
                {
                    sp_07 = cmd_02.Parameters.Add("@ypzqs", SqlDbType.Money, 40);
                    sp_08 = cmd_02.Parameters.AddWithValue("@cfhm", cfcx.s_temp.ToString());

                    sp_07.Direction = ParameterDirection.Output;

                    cmd_02.ExecuteNonQuery();

                    tb_ypzqs.Text = sp_07.Value.ToString();
                }

                //MessageBox.Show(s);

            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            s_temp = cfcx.s_temp.ToString();
            MZYW.ms_cfcx_dy cfcx_dy = new yfxt.MZYW.ms_cfcx_dy();

            cfcx_dy.Owner = this;

            cfcx_dy.Show();

            

            
        }
    }
}
